package com.web.customers;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.domain.Customer;
import com.service.CustomerService;
import com.util.AuthenticateHttpServlet;

@WebServlet("/Customer/Edit")
public class CustomerEditController extends AuthenticateHttpServlet {
 /**
	 * 
	 */
	private static final long serialVersionUID = -5091789489370823517L;

protected void post(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	
	CustomerService model = new CustomerService();
	Customer customer = new Customer(req.getParameter("customer_id"),
			                            req.getParameter("firstName"),
			                            req.getParameter("lastName"),
			                            req.getParameter("sex"),
	                                    req.getParameter("package_id"),
	                                    req.getParameter("employee_id"),
	                                    Integer.parseInt(req.getParameter("age")),	                                   
	                                    Integer.parseInt(req.getParameter("height")),
	                                    Integer.parseInt(req.getParameter("weight")));
	PrintWriter writer = resp.getWriter();
    writer.print(req.getParameter("height"));
	boolean result = model.editCustomer(customer);
	if(result) req.getRequestDispatcher("../Customer/List").forward(req, resp);
	else req.getRequestDispatcher("/WEB-INF/jsp/CustomerUpdateFailed.jsp").forward(req,resp);
}
}
